﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace DAO
{
    public class ChiTietBCTon_DAO
    {
        private static ChiTietBCTon_DAO m_instance = null;

        public static ChiTietBCTon_DAO Instance
        {
            get
            {
                if (m_instance == null)
                    m_instance = new ChiTietBCTon_DAO();
                return m_instance;
            }
        }


        /// <summary>
        ///   Them thong tiet ct bao cao
        /// </summary>
        /// 

        public bool ThemChiTietBaoCao(string _mabaocao, string _masanpham, int _tondau, int _phatsinh, int _toncuoi, int _soluongban, int _soluongmua)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("ADD_CTBAOCAOTON", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@MaBaoCaoTon", SqlDbType.NVarChar, 10);
                cmd.Parameters["@MaBaoCaoTon"].Value = _mabaocao;

                cmd.Parameters.Add("@MaSanPham", SqlDbType.NVarChar, 10);
                cmd.Parameters["@MaSanPham"].Value = _masanpham;

                cmd.Parameters.Add("@TonDau", SqlDbType.Int);
                cmd.Parameters["@TonDau"].Value = _tondau;

                cmd.Parameters.Add("@PhatSinh", SqlDbType.Int);
                cmd.Parameters["@PhatSinh"].Value = _phatsinh;

                cmd.Parameters.Add("@TonCuoi", SqlDbType.Int);
                cmd.Parameters["@TonCuoi"].Value = _toncuoi;

                cmd.Parameters.Add("@SoLuongBan", SqlDbType.Int);
                cmd.Parameters["@SoLuongBan"].Value = _soluongban;

                cmd.Parameters.Add("@SoLuongMua", SqlDbType.Int);
                cmd.Parameters["@SoLuongMua"].Value = _soluongmua;

                cmd.ExecuteNonQuery();

                return true;
            }
            catch (System.Exception ex)
            {
                return false;
            }
        }

        /// <summary>
        ///   lay danh sach ma san pham
        /// </summary>
        /// 

        public DataTable LayDanhSachMaSanPham()
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("LAY_TOANBO_MASANPHAM", cnn);
                cmd.CommandType = CommandType.StoredProcedure;


                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                da.Fill(table);

                return table;
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        ///   lay ton dau cua san pham
        /// </summary>
        /// 

        public DataTable LayTonDauCuaSanPham(string _id)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("LAY_TONDAU_BY_MASANPHAM", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@MaSanPham", SqlDbType.NVarChar, 10);
                cmd.Parameters["@MaSanPham"].Value = _id;

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                da.Fill(table);

                return table;
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        ///   lay so luong ban cua san pham
        /// </summary>
        /// 

        public DataTable LaySoLuongBanCuaSanPham(string _id)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("LAY_SOLUONGBAN", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@MaSanPham", SqlDbType.NVarChar, 10);
                cmd.Parameters["@MaSanPham"].Value = _id;

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                da.Fill(table);

                return table;
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        ///   lay so luong mua cua san pham
        /// </summary>
        /// 

        public DataTable LaySoLuongMuaCuaSanPham(string _id)
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("LAY_SOLUONGMUA", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                cmd.Parameters.Add("@MaSanPham", SqlDbType.NVarChar, 10);
                cmd.Parameters["@MaSanPham"].Value = _id;

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                da.Fill(table);

                return table;
            }
            catch (Exception)
            {
                return null;
            }
        }

        /// <summary>
        ///   lay thong tin san pham
        /// </summary>
        /// 

        public DataTable LayToanBoSanPham()
        {
            try
            {
                SqlConnection cnn = SQLConnection.Instance.SqlConnection;
                SqlCommand cmd = new SqlCommand("LAY_TOANBO_SANPHAM", cnn);
                cmd.CommandType = CommandType.StoredProcedure;

                SqlDataAdapter da = new SqlDataAdapter(cmd);
                DataTable table = new DataTable();
                da.Fill(table);

                return table;
            }
            catch (Exception)
            {
                return null;
            }
        }

    }
}
